package modulesAPI.v2.composite;

import person.Person;
import com.caterina.components.CPanel;
import controllers.PermissionList;

import modulesAPI.v2.Module;
import modulesAPI.v2.ViewType;
import modulesAPI.v2.basics.ModPermissions;
import modulesAPI.v2.basics.ModTextField;

public class MUserProfile extends Module<String> {
	public MUserProfile(Module<?> ownerModule, Person person, PermissionList permissions, String tag,String description, ViewType viewType) {
		super(ownerModule, "", tag, description, viewType);
		this.containedPermissions=permissions;
		this.containedPerson=person;
		this.createModules();
		this.addModules(this.pwdTextField,this.person,this.permissions);
	}
	@Override
	protected void beforeFireChange(Module<?> mod) {
		this.setContent(pwdTextField.getContent());
	}
	@Override
	protected void afterFireChange(Module<?> mod) {}
	@Override
	protected CPanel getInListPanel(boolean isSelected) {
		return this.getDefaultPanel();
	}
	@Override
	protected CPanel getReadOnlyPanel(boolean isSelected) {
		return this.getDefaultPanel();
	}
	@Override
	protected CPanel getWritablePanel(boolean isSelected) {
		return this.getDefaultPanel();
	}
	@Override
	protected CPanel getOneLinePanel(boolean isSelected) {
		return this.getDefaultPanel();
	}
	private void createModules(){
		this.person=new MPerson(this, containedPerson, "USER_INFO", "USER_INFO_DESC", ViewType.READ_ONLY);
		this.pwdTextField=new ModTextField(this, this.getContent(), "USER_PASSWORD_MODIFY", "USER_PASSWORD_MODIFY_DESC", ViewType.WRITABLE, ModTextField.PASSWORD);
		this.permissions=new ModPermissions(this, containedPermissions, "PERMISSIONS_INFO", "PERMISSIONS_INFO_DESC", ViewType.READ_ONLY);
	}
	private Person containedPerson;
	private PermissionList containedPermissions;
	private ModTextField pwdTextField;
	private MPerson person;
	private ModPermissions permissions;
}
